<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
	
</script>
<body>
	<!-- <div class="pageHeader">pageHeader</div> -->
	<div class="pageContent">
		<form name="customerForm" method="post" action="saveCustomerInfo"
			class="pageForm required-validate"
			onsubmit="return validateCallback(this,ajaxCallBack)">
			<div class="pageFormContent nowrap">
				<fieldset>
					<legend>客户与版权信息</legend>
					<s:hidden name="customerId" />
					<dl>
						<dd>
							<s:textfield key="customerInfo.customerName"
								name="license.customer" readonly="true" />
						</dd>
					</dl>

					<dl>
						<dd>
							<s:textfield key="venderInfo.productVersion"
								name="license.versionNumber" readonly="true" />
						</dd>
					</dl>
					<dl>
						<dd>
							<s:textarea key="venderInfo.copyRightInfo"
								name="license.copyrightInfo" cols="50" rows="5" readonly="true" />
						</dd>
					</dl>

				</fieldset>
				<fieldset>
					<legend>产品信息</legend>
					<script type="text/javascript">
						jQuery(document)
								.ready(
										function() {
											customerGrid = jQuery("#productList");
											customerGrid
													.jqGrid({
														url : "licenseProductsGrid?customerId=${customerId}",
														datatype : "json",
														mtype : "GET",
														colModel : [
																{
																	name : 'productId',
																	index : 'productId',
																	align : 'center',
																	label : '<s:text name="productInfo.productId" />',
																	hidden : false,
																	key : true,
																	width : 50
																},
																{
																	name : 'productName',
																	index : 'productName',
																	align : 'center',
																	label : '<s:text name="productInfo.productName" />',
																	width : 50

																},
																{
																	name : 'allowedUsers',
																	index : 'allowedUsers',
																	align : 'center',
																	label : '用户数',
																	width : 50,
																	editable : true,
																	editrules : {
																		integer : true
																	}

																} ],

														jsonReader : {
															root : "pageList", // (2)
															page : "page",
															total : "total",
															records : "records", // (3)
															repeatitems : false
														},

														prmNames : {
															page : "page",
															rows : "pagesize",
															sort : "sortname",
															order : "sortorder"
														},
														rowNum : 10,
														rowList : [ 5, 10, 20,
																50, 100, 200 ],
														//pager : '#productListPager',
														rownumbers : false,
														sortname : 'productId',
														sortorder : 'desc',
														//caption : '<s:text name="customerInfoList.title" />',
														height : "500",
														autowidth : true,
														loadui : "disable",
														multiselect : true,
														multiboxonly : true,
														hidegrid : false,
														onSelectRow : function(
																rowid) {

														},
														gridComplete : function() {
															resizeGrid(
																	jQuery(this),
																	-50,
																	"#productListContainer");
															/* if (jQuery(this).getDataIDs().length > 0) {
																jQuery(this)
																		.jqGrid(
																				'setSelection',
																				jQuery(this)
																						.getDataIDs()[0]);//默认选中第一行
															} */
														},
														loadComplete : function(
																data) {

														}

													});
											/* $("#productListContainer").bind("resize", function() {
												resizeGrid($("#productList"), 0,null);
											}); */
										});
						function productsGridEdit() {
							//alert("sdf");
							try {
								//var ids = jQuery(gridId).jqGrid('getDataIDs');
								var ids = jQuery("#productList").jqGrid(
										'getGridParam', 'selarrrow');
								for ( var i = 0; i < ids.length; i++) {
									var cl = ids[i];
									jQuery("#productList").editRow(cl);
								}
							} catch (err) {
								alert(err);
							}
						}
						function productGridEditCancel() {
							navTab.reload();
						}
						function saveproductGridEdit() {
							try {
								var gridId = "#productList";
								var saveUrl = "licenseGen?customerId=${customerId}";
								var ids = jQuery(gridId).jqGrid('getGridParam', 'selarrrow');
								var entityArray = "";
								for ( var i = 0; i < ids.length; i++) {
									var cl = ids[i];
									if ($($(gridId).jqGrid("getInd", cl, true))
											.attr("editable") === "1") {

										var saveparameters = {
											"url" : 'clientArray',
											"aftersavefunc" : function(rowid,
													resp, tmp,o) {
												jQuery
														.each(
																tmp,
																function(name,
																		value) {
																	if (name != "oper")
																		entityArray = entityArray
																				+ name
																				+ ":"
																				+ value
																				+ "|";
																});
												entityArray += ";";

											}
										};

										var returnRes = $(gridId).saveRow(cl,
												saveparameters);
										if (returnRes) {
											continue;
										} else {
											break;
										}
									}
								}
								jQuery
										.ajax({
											dataType : 'json',
											url : saveUrl,
											data : 'allParam=' + entityArray,
											type : 'POST',
											async : 'false',
											error : function(data) {
												//alert(data);
												/* alertMsg
														.confirm("编辑保存失败,有可能是由于编辑内容过多,请尝试每页条数在100以内！！！"); */
														//alert("fdc");
												alertMsg.error(data.ajaxMessage);
											},
											success : function(data) {
												if(data.ajaxStatus=='error')
												alertMsg.error(data.ajaxMessage);
												else
												alertMsg.correct(data.ajaxMessage);
												//location.href=url;
											}
										});

							} catch (err) {
								alert(err);
							}
						}
					</script>


					<div id="productListContainer">
						<div class="panelBar">
							<ul class="toolBar">
								<li><a class="edit" href="#"
									onclick="javaScript:productsGridEdit();"><span>编辑</span></a></li>
								<li class="line">line</li>
								<li><a class="delete" href="#"
									onclick="javaScript:productGridEditCancel();"><span>取消编辑</span></a></li>
								<li class="line">line</li>
								<li><a class="add" href="#"
									onclick="javaScript:saveproductGridEdit();"><span>添加</span></a></li>
								<li class="line">line</li>
								<li><a class="icon" href="#"
									onclick="javaScript:processGridSelectedRecords('productInfolist','disableProductInfo','确认停用吗?');"><span>停用</span></a></li>
								<li class="line">line</li>
								<li><a class="icon" href="#"
									onclick="javaScript:processGridSelectedRecords('productInfolist','enableProductInfo','确认启用吗?');"><span>启用</span></a></li>
							</ul>
						</div>
						<table id="productList"></table>
						<div id="productListPager"></div>
					</div>





				</fieldset>








				<!-- 	<div class="formBar">
					<ul>
						<li>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="submit">保存</button>
								</div>
							</div>
						</li>
						<li>
							<div class="button">
								<div class="buttonContent">
									<button type="Button" class="close">取消</button>
								</div>
							</div>
						</li>
					</ul>
				</div> -->
			</div>
		</form>

	</div>
</body>
</html>